home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / front.lha / front / src / Rules.md < prev    next >
Text File  |  1992-08-18  |  6KB  |  257 lines

  1. (* handle rule section *)
  2.  
  3. (* $Id: Rules.md,v 1.3 1991/11/21 14:47:50 grosch rel $ *)
  4.  
  5. (* $Log: Rules.md,v $
  6.  * Revision 1.3  1991/11/21  14:47:50  grosch
  7.  * new version of RCS on SPARC
  8.  *
  9.  * Revision 1.2  90/06/11  18:45:23  grosch
  10.  * layout improvements
  11.  * 
  12.  * Revision 1.1     89/01/23  15:47:43  vielsack
  13.  * by using AppendArtificialNode instead of MakeArtificialNode
  14.  * the tree order is the same as that of the input,
  15.  * this is necessary to handle LL(1) conflicts correctly
  16.  * 
  17.  * Revision 1.0     88/10/04  14:27:07  vielsack
  18.  * Initial revision
  19.  * 
  20.  *)
  21.  
  22. DEFINITION MODULE Rules;
  23.  
  24.   FROM Lists    IMPORT tList;
  25.   FROM TokenTab IMPORT Terminal, NonTerminal, Vocabulary,PosType;
  26.   FROM SYSTEM    IMPORT ADDRESS;
  27.   FROM Idents    IMPORT tIdent;
  28.  
  29.   TYPE
  30.     Operation = (Plus, Star, Optional, Bracket, Sequence, Separator, Alternative,
  31.        ArtAlternative, Action, TermLeaf, NonTermLeaf,NoOperation);
  32.  
  33.     UnaryOperation = [Plus..Star];
  34.     BracketOperation = [Optional..Bracket];
  35.     BinaryOperation = [Sequence..Alternative];
  36.     ArtificialOperation = [ArtAlternative..ArtAlternative];
  37.     LeafOperation = [TermLeaf..NonTermLeaf];
  38.     Expression;        (* eine rechte Seite *)
  39.     MRules;        (* Regeln *)
  40.  
  41.   VAR NoExpression : Expression;    (* NIL *)
  42.  
  43.   PROCEDURE MakeLeafNode
  44.     (Sym: tIdent;
  45.      Pos: PosType) : Expression;
  46.  
  47.   (* Lege neuen Blattknoten an und liefere den Zeiger auf ihn
  48.      zurueck. *)
  49.  
  50.  
  51.   PROCEDURE MakeActionNode
  52.     (Act: tList;
  53.      Pos: PosType) : Expression;
  54.   
  55.   (* Lege neuen Actionknoten an und liefere den Zeiger auf ihn
  56.      zurueck *)
  57.  
  58.   
  59.   PROCEDURE MakeUnaryNode
  60.     (Art: UnaryOperation;
  61.      Pos: PosType;
  62.      Son: Expression) : Expression;
  63.  
  64.   (* Bilde neuen Knoten der angegebenen Art mit gegebenem Sohn,
  65.      und liefere den Zeiger auf ihn zurueck *)
  66.   
  67.  
  68.   PROCEDURE MakeBracketNode
  69.     (Art: BracketOperation;
  70.      Pos,
  71.      SecPos : PosType;
  72.      Son: Expression) : Expression;
  73.  
  74.   (* Bilde neuen Knoten der angegebenen Art mit gegebenem Sohn,
  75.      und liefere den Zeiger auf ihn zurueck *)
  76.   
  77.  
  78.   PROCEDURE MakeBinaryNode
  79.     (Art : BinaryOperation;
  80.      Pos : PosType;
  81.      LSon,
  82.      RSon: Expression) : Expression;
  83.  
  84.   (* Bilde neuen Knoten der angegebenen Art mit gegebenen Soehnen,
  85.      und liefere den Zeiger auf ihn zurueck *)
  86.  
  87.  
  88.   PROCEDURE MakePrioAlternativeNode
  89.     (Pos    : PosType;
  90.      LSon,
  91.      RSon    : Expression;
  92.      HasPrio    : BOOLEAN;
  93.      PRIOPos    : PosType;
  94.      PrioSym    : tIdent;
  95.      PrioSymPos : PosType) : Expression;
  96.   
  97.   (* entspricht MakeBinaryNode (Alternative,...) jedoch wird zusaetzlich
  98.      eine Prioritaet abgespeichert *)
  99.  
  100.  
  101.   PROCEDURE AppendArtificialNode
  102.     (Pos, SecPos : PosType;
  103.      VAR Expr: Expression;
  104.      New: Expression);
  105.  
  106.   PROCEDURE PutNodeSpecial
  107.     (Exp:  Expression;
  108.      Spec: ADDRESS);
  109.   
  110.   (* Trage Knotensonderinformation ein *)
  111.      
  112.  
  113.   PROCEDURE MakeRule
  114.     (Left    : tIdent;
  115.      LeftPos    : PosType;
  116.      ColonPos    : PosType;
  117.      Right    : Expression;
  118.      Comment    : tList;
  119.      CommPos    : PosType;
  120.      PointPos    : PosType;
  121.      HasPrio    : BOOLEAN;
  122.      PRIOPos    : PosType;
  123.      PrioSym    : tIdent;
  124.      PrioSymPos : PosType);
  125.  
  126.   (* Trage eine neue Regel in die Datenstruktur ein *)
  127.  
  128.  
  129.   PROCEDURE MakeRulesHeader
  130.     (RULESPos    : PosType;
  131.      Comment    : tList;
  132.      CommPos    : PosType);
  133.  
  134.   (* Speichere globale Information zum Abschnitt RULES ab *)
  135.  
  136.  
  137.   PROCEDURE InitRulesReading(); 
  138.  
  139.   (* Setze Lesezeiger auf Anfang der Liste. Gibt nach Schreib-
  140.      zugriff Lesen am Anfang der Liste wieder frei. *)
  141.       
  142.  
  143.   PROCEDURE GetNodeOperation (Exp: Expression): Operation;
  144.  
  145.   (* Hole Typinformation ueber Expression. Bei leerer Liste wird
  146.      NoOperation zurueckgeliefert *)
  147.  
  148.  
  149.   PROCEDURE GetLeafNode
  150.     (     Exp: Expression;
  151.      VAR Voc: Vocabulary;
  152.      VAR Pos: PosType);
  153.  
  154.   (* Liefere Information aus Blattknoten. *)
  155.  
  156.  
  157.   PROCEDURE GetActionNode
  158.     (     Expr:Expression;
  159.      VAR Act: tList;
  160.      VAR Pos: PosType);
  161.   
  162.   (* Liefere Information aus Actionknoten *)
  163.  
  164.   
  165.   PROCEDURE GetUnaryNode
  166.     (     Expr:Expression;
  167.      VAR Pos: PosType;
  168.      VAR Son: Expression);
  169.  
  170.   (* Liefere Information aus unaerem Knoten *) 
  171.   
  172.  
  173.   PROCEDURE GetBracketNode
  174.     (     Expr:Expression;
  175.      VAR Pos,
  176.      SecPos : PosType;
  177.      VAR Son: Expression);
  178.  
  179.   (* Liefere Information aus Klammer-Knoten *) 
  180.   
  181.  
  182.   PROCEDURE GetBinaryNode
  183.     (     Expr: Expression;
  184.      VAR Pos : PosType;
  185.      VAR LSon,
  186.      RSon: Expression);
  187.  
  188.   (* Liefere Information aus binaerem Knoten *)
  189.  
  190.   PROCEDURE GetPrioAlternativeNode
  191.     (     Expr        : Expression;
  192.      VAR Pos        : PosType;
  193.      VAR LSon        : Expression;
  194.      VAR RSon        : Expression;
  195.      VAR HasPrio    : BOOLEAN;
  196.      VAR PRIOPos    : PosType;
  197.      VAR PrioSym    : tIdent;
  198.      VAR PrioSymPos : PosType);
  199.   
  200.   (* entspricht MakeBinaryNode (Alternative,...) jedoch wird zusaetzlich
  201.      eine Prioritaet abgespeichert *)
  202.  
  203.  
  204.   PROCEDURE GetArtificialNode
  205.     (     Expr: Expression;
  206.      VAR Pos : PosType;
  207.      VAR SecPos : PosType;
  208.      VAR LSon,
  209.      RSon: Expression);
  210.  
  211.   (* Liefere Information aus kuenstlichem Knoten *)
  212.  
  213.  
  214.   PROCEDURE GetNodeSpecial
  215.     (Exp:  Expression) : ADDRESS;
  216.   
  217.   (* Liefere Knotensonderinformation *)
  218.      
  219.  
  220.   PROCEDURE GetRule
  221.     (VAR Left        : NonTerminal;
  222.      VAR LeftPos    : PosType;
  223.      VAR ColonPos   : PosType;
  224.      VAR Right        : Expression;
  225.      VAR Comment    : tList;
  226.      VAR CommPos    : PosType;
  227.      VAR PointPos   : PosType;
  228.      VAR HasPrio    : BOOLEAN;
  229.      VAR PRIOPos    : PosType;
  230.      VAR PrioSym    : Terminal;
  231.      VAR PrioSymPos : PosType) : BOOLEAN;
  232.  
  233.   (* Liefere naechste Regel bzw. FALSE falls es keine naechste Regel
  234.      mehr gibt. Die erste Regel kann nach Aufruf von InitRulesReading
  235.      gelesen werden. Kann in Wechsel mit GetEsentialRule verwendet 
  236.      werden. *)
  237.  
  238.   PROCEDURE GetEssentialRule
  239.     (VAR Left        : NonTerminal;
  240.      VAR Right        : Expression;
  241.      VAR HasPrio    : BOOLEAN) : BOOLEAN;
  242.  
  243.   (* Liefere naechste Regel bzw. FALSE falls es keine naechste Regel
  244.      mehr gibt. Die erste Regel kann nach Aufruf von InitRulesReading
  245.      gelesen werden.Kann im Wechsel mit GetRule verwendet werden *)
  246.  
  247.   PROCEDURE GetRulesHeader
  248.     (VAR RULESPos   : PosType;
  249.      VAR Comment    : tList;
  250.      VAR CommPos    : PosType);
  251.  
  252.   (* Liefere globale Information zum Abschnitt RULES und initialisiere
  253.      fuer das Lesen mit GetRule *)
  254.   
  255.  
  256. END Rules.
  257.